import Vue from 'vue'
import API from '../config/music'

const proxy = '/music163'

function get(api) {
	return(params = null) => Vue.http.get(
		proxy + api.url(params)
	)
}

function post1(api) {
	return(params = null) => Vue.http.post(
		proxy + api.url(params)
	)
}

function post(api) {
	return(params = null) => Vue.http.post(
		proxy + api.url, api.params(params), {
			emulateJSON: true
		}
	)
}

export default {
	actions: {
		hot(handler) {
			return get(API.hot)()
		},
		discover(handler) {
			return get(API.discover)()
		},
		playlist(handler, params) {
			return get(API.playlist)(params)
		},
		search(handler, params) {
			return post1(API.search)(params)
		},
		play(handler, params) {
			return post(API.play)(params)
		}
	}
}
